package com.douqu.game.core.config.talent;

import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.e.E_ValueType;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * Created by dengbo on 2018/10/17 0017.
 */
public class TalentUpConfig extends GameObject {

    public int talentId;

    //天赋等级
    public int level;

    /**
     * 技能加成类型
     * 1.标记的普攻技能
     * 2.标记的其他技能
     * 3.标记的主将技能
     */
    public int skill;

    public int[] attrId;

    public E_ValueType valueType;

    public int value;

    public int buffId;

    //天赋升级消耗
    public GoodsData[] upCost;

    //天赋重置返还道具
    public GoodsData[] restitution;

    /**
     * 加成条件
     */
    public int condition;

    public int upAsset;

    public int openRestrictions;

    @Override
    public boolean check() {

        if(upCost == null)
        {
            LogUtils.error("Load TalentUpConfig check upCost error -> id:" + id);
            return false;
        }
        if(restitution == null)
        {
            LogUtils.error("Load TalentUpConfig check restitution error -> id:" + id);
            return false;
        }

        return super.check();
    }


    public long getAddValue(long base)
    {
        if(valueType == E_ValueType.RATIO_10000)
            return base * value / 10000;
        else
            return value;
    }

    @Override
    public boolean setVariable(String key, String value)
    {

         if("restitution".equals(key))
        {
            restitution = LoadUtils.loadGoodDataToArray(key, value);
            return LoadUtils.checkGoods(restitution, this.getClass(), key, id);
        }
        else if("upCost".equals(key))
        {
            upCost = LoadUtils.loadGoodDataToArray(key, value);
            return true;
        }
         else if("attrId".equals(key))
         {
             attrId = LoadUtils.loadIntArray(key, value);
             return true;
         }
         else if("valueType".equals(key))
         {
             valueType = E_ValueType.forNumber(Integer.parseInt(value));
             return true;
         }
        else
            return super.setVariable(key, value);
    }

}
